package com.ll.beautymall.utils;

import android.support.v4.app.Fragment;
import android.util.SparseArray;

import com.ll.beautymall.ui.home.homefragment.view.HomeFragment;
import com.ll.beautymall.ui.mine.view.MineFragment;
import com.ll.beautymall.ui.nine.view.NineFragment;
import com.ll.beautymall.ui.quality.view.QualityFragment;
import com.ll.beautymall.ui.shop.view.ShopFragment;

/**
 * Created by Administrator on 2016/10/11.
 */
public class FragmentUtil {
    private static final int FRAGMENT_HOME = 0;
    private static final int FRAGMENT_NINE = 1;
    private static final int FRAGMENT_QUALITY = 2;
    private static final int FRAGMENT_SHOP = 3;
    private static final int FRAGMENT_MINE = 4;

    public static Fragment createFragment(int index) {
        SparseArray<Fragment> fragments = new SparseArray<>();
        Fragment fragment = fragments.get(index);
        if (fragment == null) {
            switch (index) {
                case FRAGMENT_HOME:
                    fragment = new HomeFragment();
                    break;
                case FRAGMENT_NINE:
                    fragment = new NineFragment();
                    break;
                case FRAGMENT_QUALITY:
                    fragment = new QualityFragment();
                    break;
                case FRAGMENT_SHOP:
                    fragment = new ShopFragment();
                    break;
                case FRAGMENT_MINE:
                    fragment = new MineFragment();
                    break;
            }
        }
        fragments.put(index, fragment);
        return fragment;
    }
}
